package com.artislong.controller;

import com.artislong.text2sql.SqlExecutor;
import com.artislong.text2sql.SqlGenerator;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author 陈敏
 * @version ChatController.java, v 1.0 2025 07 02 23:21 chenmin Exp $
 * Created on 2025 07 02
 */
@RestController
@AllArgsConstructor
public class ChatController {

    private final SqlGenerator sqlGenerator;
    private final SqlExecutor sqlExecutor;

    @PostMapping(value = "/query")
    public ResponseEntity<QueryResponse> query(@RequestBody QueryRequest queryRequest) {
        String sqlQuery = sqlGenerator.generate(queryRequest.question());
        List<?> result = sqlExecutor.execute(sqlQuery);
        return ResponseEntity.ok(new QueryResponse(result));
    }

    record QueryRequest(String question) {
    }

    record QueryResponse(List<?> result) {
    }
}
